//
//  CSBaseViewCtrl.m
//  JiFengDaRen
//
//  Created by Lyc on 2017/8/30.
//  Copyright © 2017年 SH_iOS. All rights reserved.
//
#import "UIButton+EnlargeTouchArea.h"
#import "CSBaseViewCtrl.h"

@interface CSBaseViewCtrl ()
{
    UIButton *_backButton;
}
@end

@implementation CSBaseViewCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = KBASEBGCOLOR;

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"cs_navigationbar"] forBarMetrics:UIBarMetricsDefault];
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:KSHTEXTCOLOR,NSFontAttributeName:[UIFont systemFontOfSize:__I6Width(19)]}];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"csback"] forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 60, 30);
    [button setEnlargeEdgeWithTop:20 right:40 bottom:10 left:20];

    // 让按钮内部的所有内容左对齐
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [button addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    // 修改导航栏左边的item
    UIBarButtonItem *nagetiveSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    
    nagetiveSpace.width = -14;
    self.navigationItem.leftBarButtonItems = @[nagetiveSpace,backBarBtn,];
    _backButton = button;


}

//调整navigationBar上控件的位置
-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    if (@available(iOS 11.0, *)){
        [_backButton setFrame:CGRectMake(-14, 0,60, 30)];
    }
    
}

- (void)backAction:(UIButton *)btn{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return UIStatusBarStyleDefault;
}

@end
